﻿using nplJobsCommon.Employeer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Select
{
    public class SelectEmployeerContactPerson : DataAccessBase
    {
        public Guid EmployeerID { get; set; }
        public long ContactPersonID { get; set; }


        public SelectEmployeerContactPerson()
        {
            StoredProcedureName = StoredProcedure.Name.spSelectEmployeerContactPerson.ToString();
        }

        #region GetEmployeerContactPerson
        public List<EmployeerContactPerson> GetEmployeerContactPerson()
        {
            DataBaseHelper dbHelper;
            DataSet dsEmployeerContactPerson;

            try
            {
                SelectEmployeerContactPersonParameters selecEmployeerContactPersonParamenters = new SelectEmployeerContactPersonParameters(this.EmployeerID, this.ContactPersonID);
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dbHelper.Parameters = selecEmployeerContactPersonParamenters.Parameters;
                dsEmployeerContactPerson = dbHelper.Run(base.ConnectionString, dbHelper.Parameters);
                return GetList(dsEmployeerContactPerson);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion



        #region SQL parameters for selecting employeer contactperson by employeerid
        public class SelectEmployeerContactPersonParameters
        {
            public int CkeckUnique;
            private SqlParameter[] _parameters;

            public SelectEmployeerContactPersonParameters(Guid EmployeerID, long ContactPersonID)
            {
                this.EmployeerID = EmployeerID;
                this.ContactPersonID = ContactPersonID;
                Build();
            }

            #region spAddContact parameters
            /*
         
         */
            #endregion

            private void Build()
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter("@EmployeerID", EmployeerID),
                    new SqlParameter("@ContactPersonID", ContactPersonID),
                };

                Parameters = parameters;
            }

            public long ContactPersonID { get; set; }
            public Guid EmployeerID { get; set; }

            public SqlParameter[] Parameters
            {
                get { return _parameters; }
                set { _parameters = value; }
            }
        }
        #endregion

        #region GetList
        private List<EmployeerContactPerson> GetList(DataSet dsEmployeerContactPerson)
        {
            List<EmployeerContactPerson> employeerContactpersons;
            try
            {
                employeerContactpersons = (from n in dsEmployeerContactPerson.Tables[0].AsEnumerable()
                                           select new EmployeerContactPerson
                                               {
                                                   ContactPersonID = n.Field<Int64>("ContactPersonID"),
                                                   EmployeerID = n.Field<Guid>("EmployeerID"),
                                                   FirstName = n.Field<string>("FirstName"),
                                                   LastName = n.Field<string>("LastName"),
                                                   ContactNumber = n.Field<string>("ContactNumber"),
                                                   AlternativeNumber = n.Field<string>("AlternativeNumber"),
                                                   DesignationID = n.Field<int>("DesignationID"),
                                                   //CountryCodeID = n.Field<int>("CountryCodeID"),
                                                   TitleID = n.Field<int>("TitleID"),
                                                   Email = n.Field<string>("Email")
                                               }).ToList();

                return employeerContactpersons;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        #endregion
    }
}
